##=============================================================================
## Appendix Figure 25
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "sjPlot")

ipak(packages)

##---------
# Load data
#setwd("/Users/austinknuppe/Library/CloudStorage/Dropbox/Ukraine2022WartimeSurvey/Paper_peace/final_version_oct_2024/replication-scripts")
load("clean_ukraine_data.RData")

dat1 <- dat %>% 
  filter(wave == 0) %>%
  mutate(treated2 = factor(treated, labels = c("Control", "Survival Prime", 
                                               "Injustice Prime"))) 

fit <- glmer(compromise ~ 1 + survival_mindset + treated2 + 
                survival_mindset:treated2 + 
                (1 + survival_mindset | adm2_pcode),
              family = binomial,
              control = glmerControl(optimizer="bobyqa"),
              data = dat1)

sjPlot::plot_model(fit, 
                   type = "pred", 
                   terms = c("survival_mindset", "treated2")) +
  labs(y = "Predicted Probability of Compromise (Binary)", 
       x = "Survival Mindset",
       title = "",
       color = "Treatment") +
  theme(legend.position = "bottom",
        legend.direction = "horizontal",
        panel.spacing = unit(0.1, "lines"),
        strip.text.x = element_text(size = 18)) +
  guides(color = guide_legend(override.aes = list(fill = NA))) +
  ggtitle("Wave I: Priming Experiment (Control and Two Vignettes)") +
  hrbrthemes::theme_ipsum(axis_title_size = 18, base_size = 18, 
                          caption_size = 18, plot_title_size = 24) +
  theme(legend.position = "bottom",
        legend.direction = "horizontal",
        panel.spacing = unit(0.1, "lines"),
        strip.text.x = element_text(size = 18)) +
  guides(color=guide_legend(override.aes=list(fill=NA)))

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================